package util.libraries;

import java.io.File;
import java.util.ArrayList;

public class FileLibrary extends SubDirectoryLibrary
{

    ArrayList<File> myFiles;
    
    public FileLibrary (File dir)
    {
        super(dir);
    }


    public FileLibrary (String dir)
    {
        super(dir);
    }


    @Override
    public void addToLibrary (Object add)
    {
        myFiles.add((File) add);
        
    }


    @Override
    public Object getByIndex (int index)
    {
        return myFiles.get(index);
    }


    @Override
    public Object[] getLibrary ()
    {
        return myFiles.toArray();
    }


    @Override
    protected void initialize ()
    {
        myFiles = new ArrayList<File>();
    }


    @Override
    public Object getByID (Object id)
    {
        for (File f: myFiles){
            if (f.getName().equals(id))
                return f;
        }
        
        return null;
    }


    @Override
    public int getIndexByID (Object id)
    {
        
        return myFiles.lastIndexOf(getByID(id));
    }

}
